package com.youzi.tunnel.server.work;


import com.youzi.tunnel.server.handlers.TunnelClientChannelHandler;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;

/**
 *服务端连接启动器
 */
@Slf4j
public class UserClientBootstrap {


    private static Bootstrap userBootstrap;

    public static Bootstrap getUserBootstrap() {
        if (userBootstrap == null) {
            initUserBootstrap();
        }
        return userBootstrap;
    }

    private static void initUserBootstrap() {
        userBootstrap = new Bootstrap()
                .group(new NioEventLoopGroup())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<NioSocketChannel>() {

                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new TunnelClientChannelHandler());

                    }
                });
    }
}
